<!--
 * @Author: your name
 * @Date: 2021-09-29 10:30:29
 * @LastEditTime: 2021-09-29 14:05:47
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \smartCampus-admin\src\module\smartCampus\views\schoolConfig\schoolList\components\addSchoolPopup.vue
-->
<template>
    <sc-dialog
        :title="`${rowData.studentName}家长`"
        v-model="propValue"
        custom-class="parentListPopup"
        width="70vw"
        top="50px"
        @open="open"
        @close="$emit('input', false)"
    >
        <div class="dialog-content pr20 pl20">
            <avue-crud :table-loading="loading" ref="crud" :option="option" :data="rowData.parentList">
                <!-- 自定义列 -->
                <template slot-scope="{ row }" slot="relation">
                    <span>{{ row.relation }}</span>
                </template>
                <template slot-scope="{ row }" slot="parentName">
                    <span>{{ row.parentName || '暂未设置' }}</span>
                </template>

                <template slot-scope="{ row }" slot="deleted">
                    <el-tag :type="row.deleted === 1 ? 'danger' : 'info'">{{ row.deleted === 1 ? '已删除' : '未删除' }}</el-tag>
                </template>
                <template slot-scope="{ row }" slot="isSubscribe">
                    <el-tag :type="row.isSubscribe ? '' : 'danger'">{{ row.isSubscribe ? '已关注' : '未关注' }}</el-tag>
                </template>
            </avue-crud>
        </div>
        <div slot="footer" class="dialog-footer mt30">
            <el-button size="mini" @click="_close">关 闭</el-button>
        </div>
    </sc-dialog>
</template>
<script>
export default {
    props: {
        value: {
            type: Boolean,
            default: false,
        },
        rowData: {
            type: Object,
            default: () => ({}),
        },
    },
    data() {
        return {
            loading: true,
            isShowParentName: false, //是否显示家长姓名
        }
    },
    computed: {
        propValue: {
            get() {
                return this.value
            },
            set(nval) {
                this.$emit('input', nval)
            },
        },
        option() {
            return {
                addBtn: false,
                delBtn: false,
                editBtn: false,
                menu: false,
                header: false, //头部操作栏显影
                border: true, //边框
                stripe: false, //斑马线
                showHeader: true, //表头
                index: true, //是否显示表格序号
                indexWidth: 80, //序号列宽度
                indexLabel: '序号', //序号列名称,
                indexFixed: true, //序号列是否冻结
                column: [
                    {
                        label: '家长姓名',
                        prop: 'parentName',
                        hide: this.isShowParentName,
                    },
                    {
                        label: '孩子关系',
                        prop: 'relation',
                    },
                    {
                        label: '联系方式',
                        prop: 'parentMobile',
                    },
                    {
                        label: '是否关注了“学校通知”',
                        prop: 'isSubscribe',
                        dicData: [
                            {
                                value: false,
                                label: '未关注',
                            },
                            {
                                value: true,
                                label: '已关注',
                            },
                        ],
                    },
                    {
                        label: '软删除',
                        prop: 'deleted',
                        dicData: [
                            {
                                value: 0,
                                label: '未删除',
                            },
                            {
                                value: 1,
                                label: '已删除',
                            },
                        ],
                    },
                ],
            }
        },
    },
    methods: {
        //关闭弹窗
        _close() {
            this.$emit('input', false)
        },
        async open() {
            /* this.loading = true
            const {schoolId, id} = this.rowData
            const {code, data} = await this.$api.schoolConfig.studentList.getParentList({
                schoolId,
                id
            })
            if (code === 200) {
                this.parentList = data
                //是否显示家长姓名
                const index = data.findIndex((item) => {
                    return !!item.parentName
                })
                this.isShowParentName = (index === -1)
            }
            this.loading = false */
            const parentStr = JSON.parse(this.rowData.parentStr || '[]')

            //是否显示家长姓名
            const index = parentStr.findIndex((item) => {
                return !!item.parentName
            })
            this.isShowParentName = index === -1
            this.loading = false
        },
    },
}
</script>
<style lang="scss" scoped>
.parentListPopup {
    .dialog-content {
    }
}
</style>
